#include "Text.h"

// Initialize the instance to null
Text* Text::m_Text = 0;

Text::Text(void)
{

}

Text::~Text(void)
{
}

Text* Text::GetInstance(void)
{
	// Create the singleton if it doesn't exist
	if(!m_Text)
		m_Text = new Text;

	// Return the singleton
	return m_Text;
}

void Text::DeleteTextInstance(void)
{
	// If instance exist, delete it!
	if(m_Text)
	{
		delete m_Text;
		m_Text = NULL;
	}
}

void Text::Init(IDirect3DDevice9* m_pD3DDevice, HWND hWnd)
{
	// Create font object to use
	D3DXCreateFont(
		m_pD3DDevice,			// device
		40,0,					// height, width 0 makes it fit perfectly
		FW_BOLD,				// Weight
		0,						// Mip Level // 0 means to use all mip maps till 2x2 pixals
		false,					// Italics
		DEFAULT_CHARSET,		// character set to use
		OUT_DEFAULT_PRECIS,		// output precision
		DEFAULT_QUALITY,		// Quality
		DEFAULT_PITCH | FF_DONTCARE,	// pitch& family to use
		TEXT("Goudy Stout"),			// Font to load
		&m_pInputFont);				// ID3DFont to return

	// Create font object to use
	D3DXCreateFont(
		m_pD3DDevice,			// device
		25,0,					// height, width 0 makes it fit perfectly
		FW_BOLD,				// Weight
		0,						// Mip Level // 0 means to use all mip maps till 2x2 pixals
		false,					// Italics
		DEFAULT_CHARSET,		// character set to use
		OUT_DEFAULT_PRECIS,		// output precision
		DEFAULT_QUALITY,		// Quality
		DEFAULT_PITCH | FF_DONTCARE,	// pitch& family to use
		TEXT("Quartz MS"),			// Font to load
		&m_pFontTimer);	

	// Create font object to use
	D3DXCreateFont(
		m_pD3DDevice,			// device
		30,0,					// height, width 0 makes it fit perfectly
		FW_BOLD,				// Weight
		0,						// Mip Level // 0 means to use all mip maps till 2x2 pixals
		false,					// Italics
		DEFAULT_CHARSET,		// character set to use
		OUT_DEFAULT_PRECIS,		// output precision
		DEFAULT_QUALITY,		// Quality
		DEFAULT_PITCH | FF_DONTCARE,	// pitch& family to use
		TEXT("Quartz MS"),			// Font to load
		&m_pFontScore);

	// Create font object to use
	D3DXCreateFont(
		m_pD3DDevice,			// device
		30,0,					// height, width 0 makes it fit perfectly
		FW_BOLD,				// Weight
		0,						// Mip Level // 0 means to use all mip maps till 2x2 pixals
		false,					// Italics
		DEFAULT_CHARSET,		// character set to use
		OUT_DEFAULT_PRECIS,		// output precision
		DEFAULT_QUALITY,		// Quality
		DEFAULT_PITCH | FF_DONTCARE,	// pitch& family to use
		TEXT("Quartz MS"),			// Font to load
		&m_pFontLevel);


	// Create font object to use
	D3DXCreateFont(
		m_pD3DDevice,			// device
		40,0,					// height, width 0 makes it fit perfectly
		FW_BOLD,				// Weight
		0,						// Mip Level // 0 means to use all mip maps till 2x2 pixals
		false,					// Italics
		DEFAULT_CHARSET,		// character set to use
		OUT_DEFAULT_PRECIS,		// output precision
		DEFAULT_QUALITY,		// Quality
		DEFAULT_PITCH | FF_DONTCARE,	// pitch& family to use
		TEXT("Goudy Stout"),			// Font to load
		&m_pFontHighScore);	

	// set the string value
	sprintf_s( cOutput, 256, " ");  /// can change in update process (example update score)
	GetClientRect(hWnd, &pRect );

	// set boundaries of highscore rect
	pRectHighScore.left = 150;
	pRectHighScore.right = pRectHighScore.left + 774;
	pRectHighScore.top = 150;
	pRectHighScore.bottom = pRectHighScore.top + 618;

	// set boundaries of score rect
	pRectScore.left = 25;
	pRectScore.right = pRectScore.left + 884;
	pRectScore.top = 595;
	pRectScore.bottom = pRectScore.top + 183;

	// set boundaries of level rect
	pRectLevel.left = 745;
	pRectLevel.right = pRectLevel.left + 164;
	pRectLevel.top = 690;
	pRectLevel.bottom = pRectLevel.top + 88;

	// set boudaries of input rect
	pRectInput.left = 300;
	pRectInput.right = pRectInput.left + 624;
	pRectInput.top = 400;
	pRectInput.bottom = pRectInput.top + 365;

	// set boudaries of input rect
	pRectTimer.left = 475;
	pRectTimer.right = pRectTimer.left + 624;
	pRectTimer.top = 175;
	pRectTimer.bottom = pRectTimer.top + 365;

}

void Text::Incriment(short sNum)
{
	// clear the output
	ZeroMemory( &cOutput, sizeof(cOutput) );

	string strNum;
	ostringstream convert;
	convert << sNum;
	strNum = convert.str();
	string fileName = "Score: " + strNum;

	sprintf_s( cOutput, 256, fileName.c_str()); 
}

void Text::SetLevel(int iLevel)
{
	// clear the output
	ZeroMemory( &cOutput, sizeof(cOutput) );

	string strLevel;
	ostringstream convert;
	convert << iLevel;
	strLevel = convert.str();
	string fileName = strLevel;

	sprintf_s(cOutput, 256, fileName.c_str());
	RenderLevel();
}

void Text::SetTimer( LONG milliseconds )
{
	// clear the output
	ZeroMemory( &cOutput, sizeof(cOutput) );

	LONG seconds = milliseconds / 1000;
	milliseconds = milliseconds % 1000;
	LONG minutes = seconds / 60;
	seconds = seconds % 60;

	char strSeconds[256];
	char strMinutes[256];
	sprintf_s(strSeconds, "%d", seconds);
	sprintf_s(strMinutes, "%d", minutes);

	strcat_s(cOutput, 256, "Time Left: \n");
	strcat_s(cOutput, 256, strMinutes);
	strcat_s(cOutput, 256, ":");
	strcat_s(cOutput, 256, strSeconds);
}
void Text::SetName1(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore1(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName2(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore2(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName3(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore3(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName4(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore4(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName5(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore5(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName6(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore6(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName7(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore7(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName8(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore8(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName9(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore9(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName10(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n\n\n\n ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore10(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "\n\n\n\n\n\n\n\n\n\n\n                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetName11(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, " ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetScore11(string strHighScore)
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strhighscore[256];

	sprintf_s(strhighscore, "%s", strHighScore.c_str());

	strcat_s(cOutput, 256, "                                  ");
	RenderHighScore();
	strcat_s(cOutput, 256, strhighscore );
	RenderHighScore();
}

void Text::SetHighScore( string strLName )
{
	ZeroMemory( &cOutput, sizeof(cOutput) );

	char strName[256];

	sprintf_s(strName, "%s", strLName.c_str());

	strcat_s( cOutput, 256, "\n " );
	RenderInput();
	strcat_s( cOutput, 256,  strName);
	RenderInput();
}

void Text::RenderScore()
{
	// Draw the string
	m_pFontScore->DrawTextA(
		NULL,					// given sprite object or null
		cOutput,					// string to draw
		-1,						// length or -1(for the length it recieves
		&pRectScore,					// rect to draw txt in
		DT_TOP | DT_LEFT,		// positioning flags (this case is top right
		D3DCOLOR_ARGB(175,0,255,0) );		// color of the text
}

void Text::RenderLevel()
{
	// Draw the string
	m_pFontLevel->DrawTextA(
		NULL,					// given sprite object or null
		cOutput,					// string to draw
		-1,						// length or -1(for the length it recieves
		&pRectLevel,					// rect to draw txt in
		DT_TOP | DT_LEFT,		// positioning flags (this case is top right
		D3DCOLOR_ARGB(175,0,255,0) );		// color of the text
}

void Text::RenderHighScore()
{
	// Draw the string
	m_pFontHighScore->DrawTextA(
		NULL,					// given sprite object or null
		cOutput,					// string to draw
		-1,						// length or -1(for the length it recieves
		&pRectHighScore,					// rect to draw txt in
		DT_TOP | DT_LEFT,		// positioning flags (this case is top right
		D3DCOLOR_ARGB(255,0,255,0) );		// color of the text
}

void Text::RenderInput()
{
	// Draw the string
	m_pInputFont->DrawTextA(
		NULL,					// given sprite object or null
		cOutput,					// string to draw
		-1,						// length or -1(for the length it recieves
		&pRectInput,					// rect to draw txt in
		DT_TOP | DT_LEFT,		// positioning flags (this case is top right
		D3DCOLOR_ARGB(255,0,255,0) );		// color of the text
}
void Text::RenderTime()
{
	// Draw the string
	m_pFontTimer->DrawTextA(
		NULL,							// given sprite object or null
		cOutput,							// string to draw
		-1,								// length or -1(for the length it recieves
		&pRectTimer,							// rect to draw txt in
		DT_TOP | DT_LEFT,					// positioning flags 
		D3DCOLOR_ARGB(255,0,255,0) );	// color of the text
}